// Fill out your copyright notice in the Description page of Project Settings.

#include "SimplePuckup.h"
#include "Components/SphereComponent.h"
#include "SimpleCharacter.h"
#include "SimpleWeapon.h"
#include "HealthComponent.h"
#include "Particles/ParticleSystemComponent.h"
#include "SimpleAIPawn.h"


// Sets default values
ASimplePuckup::ASimplePuckup()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = false;
	SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));
	RootComponent = SphereComponent;

	ParticleComponent = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("ParticleComponent"));
	ParticleComponent->SetupAttachment(SphereComponent);

	AddHealth = 0;
	AddSpeed = 0;
	AddDamege = 0;
	bReplicates = true;
}

void ASimplePuckup::NotifyActorBeginOverlap(AActor* OtherActor)
{

	if (!HasAuthority()) return;

	ASimpleAIPawn*  AIPawn = Cast<ASimpleAIPawn>(OtherActor);

	if ( AIPawn || OtherActor==GetOwner())
	{
		return;
	}

	ASimpleCharacter* Player = Cast<ASimpleCharacter>(OtherActor);
	if (Player)
	{
		Player->CurrentWeapon->UpdateProjectile(AddDamege, AddSpeed);
		Player->GetHealthComponent()->UpdateHealth(AddHealth);
		Destroy();
	}
}

